package com.wzqj.agent.web.demo.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wzqj.agent.common.JsonOutput;
import com.wzqj.agent.common.SpringHelper;
import com.wzqj.agent.web.demo.domain.UserInfo;
import com.wzqj.agent.web.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 创建时间：2015-7-27 下午1:17:27
 * @author wh
 * @version 2.2
 */
@Controller("demoController")
@RequestMapping("/api/demo/user")
public class UserController {

	@Autowired
	private UserService userService;

	@RequestMapping("/showInfos")
	public @ResponseBody JSONObject showUserInfos(){

        JsonOutput output = new JsonOutput();
        UserService service = (UserService) SpringHelper.getBean("userInfoService");
        List<UserInfo> userInfos = service.getUsers();
        JSONArray data = (JSONArray) JSON.toJSON(userInfos);
        output.setErrCode(404);
        output.setMsg("资源未找到");
        output.setData(data);

        return output.toJSONObject();
	}
}
